In video encoding/decoding, to reduce, as much as possible, a bandwidth needed to transfer video data, the video data may be compressed by using multiple video compression methods. The video compression methods include: intra-frame compression and inter-frame compression. Currently, an inter-frame compression method based on motion estimation is mostly used. Specifically, a process in which an image encoding end compresses and encodes an image by using the inter-frame compression method includes: The encoding end divides a to-be-encoded image block into several sub-image blocks whose sizes are equal, then for each sub-image block, searches a reference image for an image block that most matches the current sub-image block, as a prediction block, then subtracts a corresponding pixel value of the prediction block from a corresponding pixel value of the sub-image block to obtain a residual, performs entropy encoding on a value obtained by transforming and quantizing the residual, and finally encodes encoded data such as a bit stream obtained by means of the entropy encoding and motion vector information. At an image decoding end, entropy decoding is first performed on the bit stream obtained by means of the entropy encoding, to obtain the encoded data such as the corresponding residual, and the corresponding motion vector information; and then the corresponding matching image block (that is, the foregoing prediction block) is obtained from the reference image according to the motion vector information, and then each pixel value in the matching image block and a corresponding pixel value in the residual are added to obtain each pixel value in the current sub-image block. The intra-frame prediction refers to that an image block is predicted by using information in a current image to obtain a prediction block, an encoding end obtains a pixel corresponding to the prediction block according to a prediction mode, a prediction direction, and a pixel value around the image block, the pixel of the prediction block is subtracted from a pixel of the image block to obtain a residual, and the residual is subjected to transform, quantization and entropy encoding and then written to a code stream; and a decoding end parses the code stream, a residual block is obtained after entropy decoding, inverse quantization, and inverse transform are performed on the code stream, the decoding end obtains the prediction block according to the prediction mode, the prediction direction, and the pixel value around the image block, and a pixel of the residual block and the pixel of the prediction block are added to obtain a reconstructed image block.
Currently, an encoding/decoding method frequently used in an entropy encoding/entropy decoding module is an arithmetic encoding/decoding technology, and a basic idea of the arithmetic encoding/decoding is to encode a signal source by using a real number in [0, 1). Theoretically, a fixed interval may be divided into several sub-intervals according to probabilities of stable and independent signal source symbol sequences, and any signal source symbol sequence may be denoted by using a decimal in a sub-interval corresponding to the signal source symbol sequence. When a sequence length tends to be infinite, encoding efficiency tends to be a signal source entropy rate. A basic implementation framework of the arithmetic encoding/decoding is as follows:
1. An encoded element is transformed into a binary symbol string: data of to-be-encoded syntactic elements, for example, an image unit mode, an intra-frame prediction mode, a residual coefficient, and a motion vector, is generally not binarized, while an arithmetic encoding engine can process only a binary symbol, and therefore before the syntactic elements are encoded, binarization processing needs to be performed on these syntactic elements. The so-called binarization process is a process of transforming a multivalue symbol into a binary symbol string. For example, when a value of the image unit mode cu type is 3, a binary symbol string ‘1001’ of the image unit mode may be obtained by performing binarization. The binarization process may be considered as a variable-length encoding process, and different binary symbol strings are generally obtained for same values of syntactic elements that are not common.
2. An arithmetic encoding interval is updated according to a value of a binary symbol and a probability value corresponding to the binary symbol to encode the binary symbol. Two basic parameters need to be used in an arithmetic encoding process: a probability estimation value of each symbol and a current interval value. There are only two values 0 and 1 for input symbols. A least probable symbol (LPS) indicates one of 0 and 1 whose probability estimation value is less, and whose occurrence probability is in a value range of (0, 0.5]; contrary to a definition of the LPS, a most probable symbol (MPS) indicates one of 0 and 1 whose probability estimation value is greater, and whose occurrence probability is in a value range of [0, 1). The current encoding interval is denoted by using an interval magnitude R and a lower limit value low of the current encoding interval, pLPS denotes a probability of the LPS, pMPS denotes a probability of the MPS, and pLPS+pMPS=1. The value R and the value low of the interval are updated as follows:
If the current input symbol is an MPS,RMPS=R×pMPS; andLown+1=lown; or
if the current input symbol is an LPS,RLPS=R−R×pMPS; andlown+1=lown+Rn×pMPS.
The decoding end may perform decoding to obtain a binary symbol string by maintaining the value R and the value low. A value R and a value low of an interval in a specific implementation process both have a finite precision, and therefore in an arithmetic encoding/decoding process, a normalization process needs to be used to enable an encoding interval to be limited to being within a range. A basic principle of normalization is that after R reaches a precision lower limit, the value R and the value low are doubled, and then whether the value R satisfies a precision requirement is determined. If the value R does not satisfy the precision requirement, a normalization operation continues to be performed until it is ensured that the value R satisfies the precision requirement.
When arithmetic encoding is performed, two modes generally exist: 1. General mode: in the mode, probabilities that binary symbols in a binary symbol string encoded by an arithmetic encoding engine are input are generally different from each other, and therefore the arithmetic encoding engine needs to input two parameters during encoding: a value of a to-be-encoded symbol and a probability of the symbol. To-be-encoded symbols are sequentially input in a binarized binary symbol string, and probabilities of the symbols are obtained after a probability model performs selection. 2. Bypass mode: in the mode, probabilities that binary symbols in a binary symbol string encoded by an arithmetic encoding engine are input are all the same, and generally the probabilities are set to 0.5, and therefore the arithmetic encoding engine can complete encoding as long as values of to-be-encoded symbols are input during encoding. The general mode and the bypass mode may be mixed to perform encoding/decoding, that is, a former binary symbol is encoded/decoded in the general mode, and a latter binary symbol is encoded/decoded in the bypass mode. Generally, encoding/decoding complexity of the bypass mode is lower than that of the general mode.
3. An arithmetic encoding interval is updated according to a value of a code stream symbol and a probability value corresponding to the code stream symbol to decode the binary code stream symbol. Two basic parameters need to be used in an arithmetic decoding process: a probability estimation value of each symbol and a current interval value. There are only two values 0 and 1 for input symbols. A least probable symbol indicates one of 0 and 1 whose probability estimation value is less, and whose occurrence probability is in a value range of (0, 0.5]; contrary to a definition of the LPS, a most probable symbol indicates one of 0 and 1 whose probability estimation value is greater, and whose occurrence probability is in a value range of [0, 1). The current encoding interval is denoted by using an interval magnitude R of the current encoding interval, an offset of a lower limit value of the arithmetic encoding interval is denoted by using offset, pLPS denotes a probability of the LPS, pMPS denotes a probability of the MPS, and pLPS+pMPS=1. The value R and the value offset of the interval are updated as follows:
If the current decoding symbol is an MPS,RMPS=R×pMPS; andoffsetn+1=lown; or
if the current decoding symbol is an LPS,RLPS=R−R×pMPS; andoffsetn+1=offsetn−Rn×pMPS.
The decoding end may perform decoding to obtain a binary symbol string by maintaining the value R and the value offset. A value R and a value offset of an interval in a specific implementation process both have a finite precision, and therefore in an arithmetic encoding/decoding process, a normalization process needs to be used to enable an encoding interval to be limited to being within a range. A basic principle of normalization is that after R reaches a precision lower limit, the value R and the value offset are doubled, and then whether the value R satisfies a precision requirement is determined. If the value R does not satisfy the precision requirement, a normalization operation continues to be performed until it is ensured that the value R satisfies the precision requirement.
4. Meanings of the low in the arithmetic encoding and the offset in the arithmetic decoding are not the same. The low in the arithmetic encoding denotes a lower limit of an encoding interval; the offset in the arithmetic decoding is an offset of a lower limit value in an arithmetic encoding interval. An initialized value of the low is generally 0, and an initialized value of the offset is read-in code stream information.
5. The first encoding interval and the second encoding interval that are before update in the arithmetic encoding are both arithmetic encoding intervals. In the prior art, an arithmetic encoding process mainly needs to resolve a multiplication calculation problem in an encoding interval update process, and particularly, a problem that when an arithmetic encoding symbol rate is relatively high, multiplication becomes a hardware design bottleneck because the multiplication has a relatively long calculation delay. In the prior art, a multiplication replacement operation is implemented by means of table lookup, but a table lookup operation still has complexity to some extent, and the encoding/decoding end needs to store a lookup table. Consequently, storage overheads are caused.